package com.jboost.modules.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jboost.modules.system.entity.SysAccount;
import com.jboost.modules.system.entity.SysUser;
import com.jboost.modules.system.vo.SysUserAccountVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @Author scott
 * @since 2018-12-20
 */
public interface SysAccountMapper extends BaseMapper<SysAccount> {
	/**
	  * 通过账号查询用户信息
	 * @param accountName
	 * @return
	 */
	public SysAccount getAccountByNameAndDomain(String accountName,String phone,String domain);

	/**
	 * 通过用户信息查询账号
	 * @param userId
	 * @param userName
	 * @param domain
	 * @return
	 */
	public SysAccount getAccountByUser(String userId,String userName,String domain);


	/**
	 * 根据账户ID查询合伙人产品域用户
	 * @param accountId
	 * @return
	 */
	List<SysUser> getUserByAccountIdAndDomain(@Param("accountId") String accountId, @Param("domain") String domain);

	List<SysUserAccountVo> getAllUserByAccountId(@Param("accountId") String accountId);

	@Select("select role_name from sys_role where id in (select role_id from sys_user_role where user_id in (select user_id from sys_user_account where account_id = #{accountId})) and domain = #{domain} order by create_time")
	List<String> getDomainRoleNamesByAccountId(@Param("accountId") String accountId, @Param("domain") String domain);

	IPage<SysAccount> pageAll(Page<SysUser> page, @Param("key") String key, @Param("domain") String domain);
    SysAccount getAccountByUserId(@Param("id") String id);

    SysAccount getAccountByPhone(String phone);
}
